<%--
  Created by IntelliJ IDEA.
  User: WYX
  Date: 2024/4/7
  Time: 10:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <title>day03</title>
    <style>
        table, th, td {
            border: 1px solid black;
        }
    </style>
</head>
<body style="text-align: center">
<a style="text-align: right" href="day0302.jsp">猜中历史记录</a>
<jsp:useBean id="g" class="wyx240407.Day03"/>
<%!
    String str;
    boolean flag;
%>
<form action="" method="post">
    <label>
        <input type="text" name="useNum" value="">
    </label>
    <input type="submit" value="提交"><br>
    <%
        try {
            if (request.getParameter("useNum") != null) {
                int useNum = Integer.parseInt(request.getParameter("useNum"));
                flag = g.guess(useNum);
                str = g.getHistory(g.getCount() - 1);
            } else str = "输入为空！";
        } catch (Exception e) {
            str = "输入有误！";
        }
    %>
    范围:
    <label>
        <input type="text" name="front" value="<%=g.getFront()%>" disabled>
    </label>
    到
    <label>
        <input type="text" name="rear" value="<%=g.getRear()%>" disabled>
    </label><br>
    <label>
        <input type="text" name="end" value="<%=str%>" disabled>
    </label>
</form>
<%if (g.getCount() > 1) {%>
<table style="margin: auto">
    <tr>
        <th>序号</th>
        <th>历史</th>
    </tr>
    <%for (int i = 0; i < g.getCount(); i++) {%>
    <tr>
        <td><%=i%>
        </td>
        <td><%=g.getHistory(i)%>
        </td>
    </tr>
    <%
        }
        if (flag) {
    %>
    <input type="button" name="clear" value="再来" onclick="window.location.href='day0301.jsp'">
    <%
            g.clear();
        }
    %>
</table>
<%}%>
</body>
</html>
